package com.vimi8.ebb.auth.service;

import com.vimi8.ebb.auth.dto.MessageClassDTO;
import com.vimi8.ebb.auth.dto.MessageDTO;
import com.vimi8.ebb.auth.model.MyMessage;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by think on 2016/12/22.
 */
@Mapper
public interface MyMessageService {


    /**
     * 查询某个消息类别的模板
     * @param messClass
     * @return
     */
    @Select("select mess_class as messClass,mess_type as messType,mess_class_name as messClassName,mess_title as messTitle," +
            "mess_content as messContent from message_class where mess_class=#{messClass}")
    public MessageClassDTO getMessageClassTemplate(@Param("messClass") String messClass);


    /**
     * 插入消息插入消息
     * @param myMessage
     * @return
     */
    @Insert("insert into my_message(id,message_type,message_class,message_content,release_id,receive_id,message_record_id) " +
            "values(#{id},#{messageType},#{messageClass},#{messageContent},#{releaseId},#{receiveId},#{messageRecordId})")
    public int insertMyMessage(MyMessage myMessage);


    /**
     * 根据当前登录用户的openId和消息类别查询消息。
     * @param openId
     * @param messageType
     * @return
     */
    @Select("select m.`id` as id,m.`message_class` as messageClass,m.message_title as messageTitle,m.`message_type` as messageType,m.`message_content` as messageContent," +
            " m.`create_time` as createTime,m.message_record_id as messageRecordId,m.`is_read` as isRead,m.`release_id` as releaseId from my_message as m " +
            " where m.receive_id=#{openId} and m.message_type=#{messageType} and m.`is_screen`=0")
    public List<MessageDTO> getMyMessageByType(@Param("openId") String openId, @Param("messageType") String messageType);


    /**
     * 标识已读消息
     * @param messageId
     * @return
     */
    @Update("update my_message set is_read=1 where id=#{messageId}")
    public int updateIsRead(@Param("messageId") String messageId);

    /**
     * 标识已屏蔽消息
     * @param messageId
     * @return
     */
    @Update("update my_message set is_screen=1 where id=#{messageId} and releaseId=#{releaseId} and message_type!=1")
    public int updateIsScreen(@Param("messageId") String messageId,@Param("releaseId") String releaseId);

}
